<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>BiwaScheme REPL</title>
<style type="text/css">
  div#bs-repl{
    border:1px solid black;
    padding:1em;
    width:100%;
  }
  div#bs-console{
    border:1px solid black;
    padding:1em;
    margin-top:1em;
  }
  div#bs-opecode{
    border:1px solid black;
    padding:1em;
    margin-top:1em;
  }
  span.dump_opecode{ color:orange; }
  span.dump_constant{ color:red; }
  div.bs-snippet{
    white-space:pre;
    cursor:pointer;
  }
  div.bs-snippet:hover {
    white-space:pre;
    cursor:pointer;
    background-color:darkseagreen;
  }
</style>

</head>
<body>

  <h1>
    <a href='../index.html'>BiwaScheme</a> REPL
    <small id="biwa_ver"></small>
  </h1>

  <!--<button id="test">foo</button>-->

  <div id="bs-repl">
    <table><tr><td valign="top">
      <form>
        <textarea id="bs-input" rows="10" cols="60">(print "Hello, world!")</textarea><br>
        <div style="float:right;">
          <span id="time"></span>
          <input type="button" value="eval" onclick="bs_eval()">
        </div>
        <br style="clear:both"/>
      </form>
      <div id="bs-console">
      </div>
      <div id="bs-opecode">
      </div>
    </td>
    <td valign="top">
      <div id="bs-sample">
        <h2>Sample</h2>
        <ul>
        <li><div class="bs-snippet">(+ 1 2)</div></li>
        <li><div class="bs-snippet">(not #t) </div></li>
        <li><div class="bs-snippet">(boolean=? #t #t #t) </div></li>
        <li><div class="bs-snippet">;; length by Y combinator 
(((lambda (f) 
    ((lambda (proc) (f (lambda (arg) ((proc proc) arg))))
     (lambda (proc) (f (lambda (arg) ((proc proc) arg))))))
  (lambda (self)
    (lambda (ls) 
      (if (null? ls) 0 (+ 1 (self (cdr ls))))))) 
 '(1 2 3 4 5))
        </div></li>
        <li><div class="bs-snippet">;; length by Y combinator (tail recursive)
(((lambda (f)
  ((lambda (proc) (f (lambda (arg1 arg2) ((proc proc) arg1 arg2))))
     (lambda (proc) (f (lambda (arg1 arg2) ((proc proc) arg1 arg2))))))
  (lambda (self) 
    (lambda (ls acc) 
      (if (null? ls) acc (self (cdr ls) (+ 1 acc))))))
 '(1 2 3 4 5) 0)
        </div></li>
        </ul>
      </div>
    </td></tr></table>
  </div>

<script type="text/javascript" src="../src/development_initializer.js"></script>
<script type="text/javascript">
var on_error = function(e){
  BiwaScheme.Port.current_error.put_string(e.message);
  throw(e);
};
var biwascheme = new BiwaScheme.Interpreter(on_error);
function bs_eval(){
  $("#bs-console").empty();
  var str = $("#bs-input").val();

  var opc = biwascheme.compile(str);
  var dump = (new BiwaScheme.Dumper()).dump_opc(opc);
  $("#bs-opecode").html(dump);
  var before = new Date();
  biwascheme.evaluate(str, function(result){
    var after = new Date();
    $("#time").html("Time: " + (after-before)/1000 + "sec");
    BiwaScheme.Port.current_output.put_string(BiwaScheme.to_write(result));
  });

  return false;
}
$(".bs-snippet").click(function(e){
  $("#bs-input").html($(this).html());
});
$("#biwa_ver").append("("+BiwaScheme.Version+")");
</script>

</body>
</html>
<!-- vim:set ft=javascript: -->
